﻿
module Sustainalytics.CompanySearch {

    import Common = Sustainalytics.Common;
    import Company = Sustainalytics.Company;
    import SearchBox = Sustainalytics.SearchBox;


    export class CompanySearchBoxServiceAdapter implements SearchBox.ISearchBoxService
    {
        // Ctor.
        public constructor(private companySearchService: Company.ICompanyService) {
        }

        // Search for items given a term and paging options
        public Search(searchData: any, skip: number, take: number): ng.IHttpPromise<any[]> {
            // get companies paged list
            var lstPromise: ng.IHttpPromise<Company.CorporateDataExtendedDto[]> = this.companySearchService.search(searchData, skip, take);
            return lstPromise;
        }
    }


    // get/create company search module
    var companySearchModule = angular.module('Sustainalytics.CompanySearch');

    // register company search service adapter angular service factory
    companySearchModule.factory('CompanySearchBoxServiceAdapter', function ($http, $q, $rootScope, notificationFactory, staticObjects, UserInfoService) {

        // create company search service
        var companySearchService = new Company.CompanyService($http, $q, $rootScope, notificationFactory, staticObjects, UserInfoService);

        // create service adapter
        var adapter = new Sustainalytics.CompanySearch.CompanySearchBoxServiceAdapter(companySearchService);

        return adapter;
    });
}